<?php
/**
 * Created by PhpStorm.
 * User: huynguyen
 * Date: 9/19/14
 * Time: 10:10 PM
 */

namespace Backend\Modules\Video\Forms;


use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Submit;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Identical;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\Confirmation;

class FormCreateNational extends Form
{
    public function initialize($name = null,$short_name = null)
    {
        $name = new Text('name' , array(
            'class' => 'form-control col-xs-12',
            'placeholder' => 'Type national',
            'value' => $name
        ));
        $name->setLabel('Quốc Gia');
        $name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Vui lòng nhập tên'
            ))
        ));
        $this->add($name);

        $short_name = new Text('short_name',array(
            'class' => 'form-control col-xs-12',
            'placeholder'   => 'Type short national',
            'value' => $short_name
        ));
        $short_name->setLabel('Viết Tắt');
        $short_name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Vui lòng nhập tên viết tắt'
            ))
        ));
        $this->add($short_name);
        // CSRF
        $csrf = new Hidden('csrf');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
        )));

        $this->add($csrf);

        // Sign Up
        $this->add(new Submit('Add', array(
            'class' => 'btn btn-primary'
        )));

    }

    public function messages($name)
    {
        if($this->getMessagesFor($name))
        {
            foreach ($this->getMessagesFor($name) as $message)
            {
                $this->flash->error($message);
            }
        }
    }
}